import React, { Component } from 'react';
import {
    Text,
    Image,
    View,
    ScrollView,
    TouchableOpacity,
} from 'react-native';
import DiagnoseCSS from '../../../../css/personal/diagnose';
import api from '../../../../api';
export default class Personal extends Component {

    // 此处设置 Tab 的名称和一些样式，这里的会覆盖掉配置路由文件的样式
    // static navigationOptions = {

    // }; 

    constructor(props) {
        super(props) 
        this.state = {
          filterNum: 1,
          data:[]
        }
    }

    componentDidMount() {

        this.getList();

      }

      getList() {
        api.expert.diagnose({'login-token':localStorage.token}).then(response => {   
          this.setState({
            data: response
          })
        })
      }
    getFilter() {
        const { navigate } = this.props.navigation;
        if(this.state.filterNum === 1) {
            return (
                <View style={[DiagnoseCSS.messages]}>
                    {
                      this.state.data.map((item,id) => {
                        
                         if(item.status==2){
                    return (
                    <TouchableOpacity key={id} onPress={() => navigate('Solved',{itm:item})} style={[DiagnoseCSS.message]}>
                        <Text style={[DiagnoseCSS.causesLabel]}>{item.title}</Text>
                    </TouchableOpacity>
                       )
                    }
                    })

                   }
                </View>
            )
        } else if(this.state.filterNum === 2) {
            return (
                <View style={[DiagnoseCSS.messages]}>
                    {
                      this.state.data.map((item,id) => {
                        
                     if(item.status!=2){
                    return (
                    <TouchableOpacity key={id} onPress={() => navigate('Suspending',{itm:item})} style={[DiagnoseCSS.message]}>
                        
                        <View style={[DiagnoseCSS.list]}>
                            <Text style={[DiagnoseCSS.causesLabel]}>未进行处理</Text>
                        </View>

                        <View style={[DiagnoseCSS.infors]}>
                            <Text style={[DiagnoseCSS.phoneNumber]}>牧民电话：{item.husername}</Text>
                        </View>

                    </TouchableOpacity>
                        )
                    }
                    })

                   }
                </View>
            )
        } 
    }
    render() {
        const { navigate } = this.props.navigation;
        return (
            <ScrollView>
                <View style={DiagnoseCSS.container}>
                    <View style={[DiagnoseCSS.header]}>
                        <TouchableOpacity style={[DiagnoseCSS.backImg]} onPress={() => { this.props.navigation.goBack(null) }}>
                            <Image source={require('../../../../img/nav_back01.png')} />
                        </TouchableOpacity>
                        <View style={DiagnoseCSS.headerText}>
                            <Text style={[DiagnoseCSS.titleText]}>诊断管理</Text>
                        </View>         
                    </View>
                    <View style={DiagnoseCSS.studys}>
                        <View style={DiagnoseCSS.tabs}>
                            <TouchableOpacity onPress={() => { this.setState({ filterNum: 1 }) }} style={[DiagnoseCSS.headeritem,DiagnoseCSS.headeritemborder]}>
                                <Text style={DiagnoseCSS.article}>已处理</Text>
                            </TouchableOpacity>
                            <TouchableOpacity onPress={() => { this.setState({ filterNum: 2 }) }} style={[DiagnoseCSS.headeritem,DiagnoseCSS.headeritemborder]}>
                                <Text style={DiagnoseCSS.video}>未处理</Text>
                            </TouchableOpacity>
                        </View>
                    </View>
                    { this.getFilter() }
                    
                </View>
            </ScrollView>
        );
    }
}